/* eslint-disable @typescript-eslint/no-var-requires */
import { Injectable } from '@nestjs/common';
import { User } from 'src/entity/User';
import CatsMapping from '../mapping/UserMapping';
const { getSqlResult, getQueryResult } = require('../utils/node-mybatis/DB');
const { outputSQL } = require('../utils/node-mybatis/SqlCompile');

@Injectable()
export class UserService {
  async getUser(id: number): Promise<any[]> {
    const sql = outputSQL(CatsMapping.findById, { id });
    const result = await getSqlResult(sql);
    console.log('result444', result);
    return result;
  }

  async createUser(user: User): Promise<any[]> {
    const sql = outputSQL(CatsMapping.insert, {
      username: user.username,
      sex: user.sex,
      address: user.address,
    });
    const result = await getSqlResult(sql);
    return result;
  }
  async delete(connection, id: string): Promise<any> {
    const sql = outputSQL(CatsMapping.delete, { id: id });
    const result = await getQueryResult(connection, sql);
    return result;
  }
}
